package demo.spark.model

import com.alibaba.fastjson.JSON
import com.alibaba.fastjson.serializer.SerializerFeature

class UserInfo(id: Int,name: String,age: Int,hobby: Array[String],week: Map[String,String]) extends Serializable {
  //辅助构造器，构造的UserInfo都是null.
  def this() {
    this(0,"",0,null,null);
  }

  def format():String = {
    return UserInfo.formatTemp.format(id,name,age,
      JSON.toJSONString(hobby,SerializerFeature.MapSortField),
      JSON.toJSONString(week,SerializerFeature.MapSortField),
    )
  }
}


object UserInfo{
  private val formatTemp:String = "id:%s, name:%s, age:%s, hobby:%s, week:%s";
}
